<!--
 * @Author: HaiF
 * @Date: 2020-12-01 22:55:42
 * @LastEditTime: 2020-12-02 23:46:25
 * @LastEditors: your name
 * @Description: 组织机构
 * @FilePath: \adminPC\src\views\user\widget\orgTree.vue
 * @可以输入预定的版权声明、个性签名、空行等
-->

<template>
  <el-tree
    ref="tree"
    :data="dataList"
    :props="defaultProps"
    check-strictly
    show-checkbox
    node-key="id"
    @check="handleCheckChange"
  />
</template>

<script>
import { getOrgTree } from '@/api/org'

export default {
  name: 'OrgTree',
  components: {},
  props: {},
  data() {
    return {
      list: [],
      defaultProps: {
        // children: 'children',
        label: 'title'
      }
    }
  },
  computed: {
    dataList() {
      const result = this.list
      return result
    }
  },
  watch: {},
  created() {
    this.getOrgTree()
  },
  mounted() {},
  methods: {
    handleCheckChange(obj, node) {
      this.$refs['tree'].setCheckedKeys([])
      this.$emit('treeClick', { target: obj, node })

      this.$nextTick(() => {
        this.$refs.tree.setCheckedKeys([obj.id])
      })
    },
    getOrgTree() {
      getOrgTree().then(res => {
        const { data, code } = res
        if (code === 200) {
          this.list = data
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.wrapper{
   padding: 0px;
   margin: 0px;
}
</style>
